package com.wgj.android.ui.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.jiaai.xui.utils.imageload.XImage;
import com.wgj.android.R;
import com.wgj.android.fragment.ShopFragment;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StoreDetailsActivity extends AppCompatActivity {
    @BindView(R.id.im_bg)
    ImageView imBg;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    private MyPagerAdapter pageAdapter;
    private List<Fragment> fragments = new ArrayList<>();
    @BindView(R.id.tv_view_page)
    ViewPager tvViewPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store_details);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {

        ShopFragment shopFragment1 = new ShopFragment();
        Bundle bundle1 = new Bundle();
        bundle1.putInt("brandId", 1);
        shopFragment1.setArguments(bundle1);

        ShopFragment shopFragment2 = new ShopFragment();
        Bundle bundle2 = new Bundle();
        bundle2.putInt("brandId", 1);
        shopFragment2.setArguments(bundle2);

        ShopFragment shopFragment3 = new ShopFragment();
        Bundle bundle3 = new Bundle();
        bundle3.putInt("brandId", 1);
        shopFragment3.setArguments(bundle3);

        ShopFragment shopFragment4 = new ShopFragment();
        Bundle bundle4 = new Bundle();
        bundle4.putInt("brandId", 1);
        shopFragment4.setArguments(bundle4);
        fragments.add(shopFragment1);
        fragments.add(shopFragment2);
        fragments.add(shopFragment3);
        fragments.add(shopFragment4);
        tablayout.setupWithViewPager(tvViewPage);
        pageAdapter = new MyPagerAdapter(getSupportFragmentManager());
        tvViewPage.setAdapter(pageAdapter);
        //tvViewPage.setOffscreenPageLimit(8);

    }

    public class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }


        @Override
        public int getCount() {
            return fragments.size();
        }
    }
}
